﻿if not _G.UnitClassBase then
	-- don't load if not running at least engine 2.4
	return
end

if select(6, GetAddOnInfo("PitBull_" .. (debugstack():match("[i%.][t%.][B%.]ull\\Modules\\(.-)\\") or debugstack():match("[i%.][t%.][B%.]ull\\(.-)\\") or ""))) ~= "MISSING" then return end

if select(2, UnitClass("player")) ~= "SHAMAN" then
	-- don't load if player is not a shaman.
	return
end

local VERSION = tonumber(("$Revision: 42 $"):match("%d+"))

local PitBull = PitBull
local PitBull_TotemTimers = PitBull:NewModule("TotemTimers", "LibRockEvent-1.0", "LibRockTimer-1.0")
local self = PitBull_TotemTimers
PitBull:ProvideVersion("$Revision: 42 $", "$Date: 2008-03-07 16:41:19 +0000 (Fri, 07 Mar 2008) $")

local _G = _G
local GetTime = _G.GetTime

-- dummy translation for now, just included for reference (implementation coming soon)
local localization = (GetLocale() == "deDE") and {
	["English text"] = "Uebersetzter Text.",
} or (GetLocale() == "xxYY") and {
	["English text"] = "Translated text.",
} or {}

local L = PitBull:L("PitBull-TotemTimers", localization)
self.desc = L["Shows Totem timers for the Pitbull player frame."]

local newFrame, delFrame = PitBull.newFrame, PitBull.delFrame

self:RegisterPitBullChildFrames('totemTimersFrame')
-- We act as a PitBullIcon. why? because it makes PB give us nice alignment options
-- TODO: find a way to only get the alignment option and not the sizing one
self:RegisterPitBullIconLayoutHandler('totemTimersFrame', 7)

local unitsShown = {}

---------------------------------------------------------------------------
-- CONFIGURATION FUNCTIONS
local function getHide()
	return self.db.profile.hidden
end
local function getEnabled()
	return not self.db.profile.hidden
end
local function setEnabled(value)
	value = not value
	self.db.profile.hidden = value
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if value then
			self:OnClearUnitFrame("player", frame)
		else
			self:OnPopulateUnitFrame("player", frame)
			self:OnUpdateFrame("player", frame)
		end
		PitBull:UpdateLayout(frame)
	end
end

local function getTotemDirection()
	return self.db.profile.totemdirection
end
local function setTotemDirection(value)
	self.db.profile.totemdirection = value
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		self:RealignTotems(frame)
	end
	
	return true
end
local function getTotemSize()
	return self.db.profile.totemsize
end
local function setTotemSize(value)
	self.db.profile.totemsize = value
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if frame.totemTimersFrame then
			local elements = frame.totemTimersFrame.elements
			for i=1, MAX_TOTEMS do
				elements[i].frame:SetHeight(value)
				elements[i].frame:SetWidth(value)
				elements[i].text:SetWidth(value)
				elements[i].text:SetHeight((value/3))
			end
			self:ResizeMainFrame(frame)
		end
	end
	
	return true
end
local function getTotemSpacing()
	return self.db.profile.totemspacing
end
local function setTotemSpacing(value)
	self.db.profile.totemspacing = value
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		self:RealignTotems(frame)
	end
	
	return true
end

local function getTotemTooltips()
	return self.db.profile.totemtooltips
end
local function setTotemTooltips(value)
	self.db.profile.totemtooltips = value
	return true
end

local function getMainBGColor()
	return unpack(self.db.profile.mainbgcolor)
end
local function setMainBGColor(r,g,b,a)
	self.db.profile.mainbgcolor = {r, g, b, a}
	
	-- Apply color to existing background
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if frame.totemTimersFrame then
			frame.totemTimersFrame.texture:SetTexture(r,g,b,a)
		end
	end
	return true
end


local function getTimerSpiral()
	return self.db.profile.timerspiral
end
local function setTimerSpiral(value)
	self.db.profile.timerspiral = value
	return true
end
local function getSuppressOCC()
	return self.db.profile.suppressocc
end
local function setSuppressOCC(value)
	self.db.profile.suppressocc = value
	return true
end


local function getTimerText()
	return self.db.profile.timertext
end
local function setTimerText(value)
	self.db.profile.timertext = value
	return true
end

local function getTimerTextColor()
	return unpack(self.db.profile.timertextcolor)
end
local function setTimerTextColor(r,g,b,a)
	self.db.profile.timertextcolor = {r, g, b, a}
	
	-- Apply color to existing strings
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if frame.totemTimersFrame then
			local elements = frame.totemTimersFrame.elements
			for i=1, MAX_TOTEMS do
				elements[i].text:SetTextColor(r,g,b,a)
			end
		end
	end
	return true
end

local function getTimerTextSide()
	return self.db.profile.timertextside
end
local function setTimerTextSide(value)
	self.db.profile.timertextside = value
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		self:RealignTimerTexts(frame)
	end
	
	return true
end

local function getTimerTextScale()
	return self.db.profile.timertextscale
end
local function setTimerTextScale(value)
	self.db.profile.timertextscale = value
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		self:RealignTimerTexts(frame)
	end
	
	return true
end

--------------------------------------------------------------------------------
-- this function is borrowed from Got Wood which got it from neronix. 
function PitBull_TotemTimers:SecondsToTimeAbbrev(time)
	local m, s
	if( time < 0 ) then
		text = ""
	elseif( time < 3600 ) then
		m = floor(time / 60)
		s = mod(time, 60)
		if (m==0) then 
			text = format("0:%02d", s)
		else
			text = format("%01d:%02d", m, s)
		end
	end
	return text
end

------------------------------------------------------------
-- Totem Logic

function PitBull_TotemTimers:OneOrMoreDown()
	--local self = PitBull_TotemTimers
	for i=1, MAX_TOTEMS do
		if ( self.totemIsDown[i] == true ) then
			return true
		end
	end
	-- none is down
	return false
end

function PitBull_TotemTimers:UpdateAllTimes()
	local mf = nil
	--local self = PitBull_TotemTimers
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if not frame.totemTimersFrame then
			PitBull:Print("ERROR: Update time called but no Totemtimer Frame initialized.")
			return
		else
			mf = frame
		end
	end
	local elements = mf.totemTimersFrame.elements
	
	local nowTime = math.floor(GetTime())
	for slot=1, MAX_TOTEMS do
		--local endTime = self.startTimes[slot] + self.durations[slot]
		--local timeleft = endTime - nowTime
		local timeleft = GetTotemTimeLeft(slot)
		--PitBull:Print(string.format("now = %f, start = %f, duration = %d",nowTime,self.startTimes[slot], self.durations[slot]))
		
		if timeleft > 0 then
			-- need to update shown time
			if ( getTimerText() ) then
				elements[slot].text:SetText(self:SecondsToTimeAbbrev(timeleft))
			else
				elements[slot].text:SetText("")
			end
			-- Hide the cooldown frame if it's shown and the user changed preference
			if ( not getTimerSpiral() and elements[slot].spiral:IsShown() ) then
				elements[slot].spiral:Hide()
			end
		else
			-- Totem expired
			elements[slot].frame:SetAlpha(0.5)
			elements[slot].text:SetText("")
			elements[slot].spiral:Hide()
		end	
	end
end

function PitBull_TotemTimers:ActivateTotem(slot)
	--local self = PitBull_TotemTimers
	local haveTotem, name, startTime, duration, icon = GetTotemInfo(slot)
	-- queried seperately because GetTotemInfo apprears to give less reliable results (wtf?!)
	local timeleft = GetTotemTimeLeft(slot)
	
	if ( name == "" ) then
		PitBull:Print("WARNING: Can't activate a nondropped totem")
		return
	end
	
	self.totemIsDown[slot] = true
	self.startTimes[slot] = startTime
	self.durations[slot] = duration
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if not frame.totemTimersFrame then
			return
		end

		local tframe = frame.totemTimersFrame.elements[slot].frame
		local ttext = frame.totemTimersFrame.elements[slot].text
		local tspiral = frame.totemTimersFrame.elements[slot].spiral
		
		tframe:SetNormalTexture(icon)
		tframe:SetAlpha(1)
		tframe:Show()
		if ( getTimerText() ) then
			ttext:SetText(self:SecondsToTimeAbbrev(timeleft))
		end
		tspiral:SetCooldown(startTime, timeleft)
		if ( getTimerSpiral() ) then
			tspiral:Show()
		else
			tspiral:Hide()
		end
		if not self:HasTimer("pbtotemtimerall") then
			self:AddRepeatingTimer("pbtotemtimerall", 0.5, function() PitBull_TotemTimers:UpdateAllTimes() end)
		end
	end
end

function PitBull_TotemTimers:DeactivateTotem(slot)
	--local self = PitBull_TotemTimers
	local haveTotem, name, startTime, duration, icon = GetTotemInfo(slot)
	
	if ( name ~= "" ) then
		PitBull:Print("WARNING: Can't deactivate a dropped totem")
		return
	end
	
	self.totemIsDown[slot] = false
	self.startTimes[slot] = 0
	self.durations[slot] = 0
	
	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if not frame.totemTimersFrame then
			return
		end

		local tframe = frame.totemTimersFrame.elements[slot].frame
		local ttext = frame.totemTimersFrame.elements[slot].text
		local tspiral = frame.totemTimersFrame.elements[slot].spiral
		
		-- cleanup timer event if no totems are down
		if not self:OneOrMoreDown() then
			if self:HasTimer("pbtotemtimerall") then
				self:RemoveTimer("pbtotemtimerall")
			end
		end
		tspiral:Hide()
		tframe:SetAlpha(0.5)
		ttext:SetText("")
	end
end


function PitBull_TotemTimers:GetTotemStatus()
	--local self = PitBull_TotemTimers
	for i=1, MAX_TOTEMS do
		local haveTotem, name, startTime, duration, icon = GetTotemInfo(i)
		if (name ~= "") then
			self.totemIsDown[i] = true
			self.startTimes[i] = startTime
			self.durations[i] = duration
			-- TODO: Must run the rest of the enabling stuff also to be useful (frame modifications, etc.)
		else
			self.totemIsDown[i] = false
			self.startTimes[i] = 0
			self.durations[i] = 0
		end
	end
end

-----------------------------------------------------
-- General addon logic

function PitBull_TotemTimers:OnInitialize()
	self.db = PitBull:GetDatabaseNamespace("TotemTimers")
	PitBull:SetDatabaseNamespaceDefaults("TotemTimers", "profile", {
		hidden = false,
		totemsize = 25,
		totemspacing = 0,
		totemdirection = "h",
		totemtooltips = true,
		timerspiral = true,
		suppressocc = true,
		timertext = true,
		timertextcolor = {1, 1, 0, 1},
		timertextside = "bottominside",
		timertextscale = 0.8,
		mainbgcolor = {0, 0, 0, 0.5},
	})
	
	-- Initialize Timer variables
	self.startTimes = {}
	self.durations = {}
	self.totemIsDown = {}
	for i=1,MAX_TOTEMS do
		self.startTimes[i] = 0
		self.durations[i] = 0
		self.totemIsDown[i] = false
	end
	
	-- Get initial status
	self:GetTotemStatus()
end

function PitBull_TotemTimers:OnEnable(first)
	self:AddEventListener("PLAYER_TOTEM_UPDATE")
end

function PitBull_TotemTimers:PLAYER_TOTEM_UPDATE(something, event, slot)
	--PitBull:Print(string.format("Got %s and %s", tostring(event), tostring(slot)))
	local haveTotem, name, startTime, duration, icon = GetTotemInfo(slot)
	local sSlot = tostring(slot)

	for frame in PitBull:IterateUnitFramesForUnit("player") do
		if not frame.totemTimersFrame then
			self:OnPopulateUnitFrame("player", frame)
			if frame.totemTimersFrame then
				PitBull:UpdateLayout(frame)
			end
		end
		
		if ( haveTotem and name ~= "") then
			-- New totem created
			--PitBull:Print("Activating Totem")
			self:ActivateTotem(slot)
		elseif ( haveTotem ) then
			-- Totem just got removed or killed.
			--PitBull:Print("Deactivating Totem")
			self:DeactivateTotem(slot)
		end
	end
end

function PitBull_TotemTimers:OnUpdateFrame(unit, frame)
	if frame.totemTimersFrame then
		self:Update(unit, frame)
	end
end

function PitBull_TotemTimers:Update(unit, frame)
	if frame.totemTimersFrame then
		PitBull:UpdateLayout(frame)
	end
end

function PitBull_TotemTimers:ResizeMainFrame(frame)
	if not frame.totemTimersFrame then
		return
	end
	local tSize = getTotemSize()
	local tSpacing = getTotemSpacing()
	local ttf = frame.totemTimersFrame
	if (getTotemDirection() == "h") then
		ttf:SetWidth((MAX_TOTEMS*tSize)+((MAX_TOTEMS-1)*tSpacing))
		ttf:SetHeight(tSize)
	else
		ttf:SetWidth(tSize)
		ttf:SetHeight((MAX_TOTEMS*tSize)+((MAX_TOTEMS-1)*tSpacing))
	end
	--PitBull:Print(string.format("Set the size of the main frame to: %d and %d",ttf:GetWidth(),ttf:GetHeight()))
end

function PitBull_TotemTimers:RealignTotems(frame)
	if frame.totemTimersFrame then
		self:ResizeMainFrame(frame)

		local elements = frame.totemTimersFrame.elements
		for i=1, MAX_TOTEMS do
			if i==1 then
				elements[i].frame:ClearAllPoints()
				elements[i].frame:SetPoint("TOPLEFT", frame.totemTimersFrame, "TOPLEFT", 0, 0)
			else
				elements[i].frame:ClearAllPoints()
				-- Attach the button to the previous one
				if (getTotemDirection() == "h") then
					-- grow horizontally
					elements[i].frame:SetPoint("TOPLEFT", elements[i-1].frame, "TOPRIGHT", getTotemSpacing(), 0)
				else
					--grow vertically
					elements[i].frame:SetPoint("TOPLEFT", elements[i-1].frame, "BOTTOMLEFT", 0, 0-getTotemSpacing())
				end
			end
		end
		self:RealignTimerTexts(frame)
	end
end

local function TimerTextAlignmentLogic(frame, parent, side, offsetX, offsetY) 
	if ((not frame) or (not parent)) then
		return
	end
	
	local offX = offsetX or 0
	local offY = offsetY or 0
	frame:ClearAllPoints()
	if side == "topinside" then
		frame:SetPoint("TOP", parent, "TOP", offX, offY)
	elseif side == "topoutside" then
		frame:SetPoint("BOTTOM", parent, "TOP", offX, offY)
	elseif side == "bottominside" then
		frame:SetPoint("BOTTOM", parent, "BOTTOM", offX, offY)
	elseif side == "bottomoutside" then
		frame:SetPoint("TOP", parent, "BOTTOM", offX, offY)
	elseif side == "leftoutside" then
		frame:SetPoint("RIGHT", parent, "LEFT", offX, offY)
	elseif side == "rightoutside" then
		frame:SetPoint("LEFT", parent, "RIGHT", offX, offY)
	elseif side == "middle" then
		frame:SetPoint("CENTER", parent, "CENTER", offX, offY)
	else
		return
	end
	
end

function PitBull_TotemTimers:RealignTimerTexts(frame)
	if frame.totemTimersFrame then
		local elements = frame.totemTimersFrame.elements
		for i=1, MAX_TOTEMS do
			if (elements[i].text) then
				TimerTextAlignmentLogic(elements[i].text, elements[i].textFrame, getTimerTextSide(), 0, 0)
				local font, fontsize = PitBull:GetFont()
				elements[i].text:SetFont(font, fontsize * getTimerTextScale(), "OUTLINE")
			end
		end
	end
end

function PitBull_TotemTimers:ButtonOnClick(mousebutton)
	if (mousebutton == "RightButton" and this.slot ) then
		DestroyTotem( this.slot )
	end
end

function PitBull_TotemTimers:ButtonOnEnter()
	if ( this.slot and getTotemTooltips() ) then
		-- setting the tooltip
		GameTooltip_SetDefaultAnchor(GameTooltip, this);
		GameTooltip:SetTotem(this.slot);
	end
end

function PitBull_TotemTimers:ButtonOnLeave()
	if ( getTotemTooltips() ) then
		-- hiding the tooltip
		GameTooltip:Hide();
	end
end

function PitBull_TotemTimers:OnPopulateUnitFrame(unit, frame)
	if unit ~= "player" or frame.totemTimersFrame or self.db.profile.hidden then
		return
	end
	
	local font, fontsize = PitBull:GetFont()
	
	local totemTimersFrame = newFrame("Frame", frame)
	local tSize = getTotemSize()
	local tSpacing = getTotemSpacing()
	
	if (getTotemDirection() == "h") then
		totemTimersFrame:SetWidth((MAX_TOTEMS*tSize)+((MAX_TOTEMS-1)*tSpacing))
		totemTimersFrame:SetHeight(tSize)
	else
		totemTimersFrame:SetWidth(tSize)
		totemTimersFrame:SetHeight((MAX_TOTEMS*tSize)+((MAX_TOTEMS-1)*tSpacing))
	end
	--totemTimersFrame:SetPoint("BOTTOMLEFT", frame, "TOPLEFT")
	--totemTimersFrame:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT")
	totemTimersFrame:Show()
	
	
	totemTimersFrame.texture = totemTimersFrame:CreateTexture(nil, "BACKGROUND");
	totemTimersFrame.texture:SetTexture(getMainBGColor());
	totemTimersFrame.texture:SetAllPoints(totemTimersFrame);
	

	frame.totemTimersFrame = totemTimersFrame
	--frame.totemTimersFrame:Hide()
	local elements = {}
	for i=1, MAX_TOTEMS do
		elements[i] = {}
		elements[i].frame = newFrame("Button", frame.totemTimersFrame)
		elements[i].frame:SetWidth(tSize)
		elements[i].frame:SetHeight(tSize)
		elements[i].frame:Hide()
		elements[i].frame.slot = i
		
		elements[i].spiral = newFrame("Cooldown", elements[i].frame)
		elements[i].spiral:SetReverse(true)
		elements[i].spiral:SetAllPoints(elements[i].frame)
		if ( getSuppressOCC() ) then
			-- user wishes to suppress omnicc on his timer spiral, requires recent (post-2.4) omnicc version!
			elements[i].spiral.noomnicc = true
		end
		
		elements[i].textFrame = newFrame("Frame", elements[i].frame)
		elements[i].textFrame:SetAllPoints(elements[i].frame)
		elements[i].textFrame:SetFrameLevel(elements[i].spiral:GetFrameLevel() + 7)
		
		elements[i].text = newFrame("FontString", elements[i].frame, "OVERLAY")
		elements[i].text:SetWidth(tSize)
		elements[i].text:SetHeight((tSize/3))
		elements[i].text:ClearAllPoints()
		elements[i].text:SetPoint("BOTTOM", elements[i].textFrame, "BOTTOM", 0, 0)
		elements[i].text:SetFont(font, fontsize * getTimerTextScale(), "OUTLINE")
		elements[i].text:SetShadowColor(0,0,0,1)
		elements[i].text:SetShadowOffset(0.8, -0.8)
		if ( getTimerTextColor() ) then
			elements[i].text:SetTextColor(getTimerTextColor())
		end
		
		elements[i].text:Show()
		
		-- click handling for destroying single totems
		elements[i].frame:RegisterForClicks("RightButtonUp")
		elements[i].frame:SetScript("OnClick", self.ButtonOnClick)
		-- tooltip handling
		elements[i].frame:SetScript("OnEnter", self.ButtonOnEnter)
		elements[i].frame:SetScript("OnLeave", self.ButtonOnLeave)
		
	end
	
	frame.totemTimersFrame.elements = elements
	self:RealignTotems(frame)
	
end

function PitBull_TotemTimers:OnUnknownLayout(unit, frame, name)
	--PitBull:Print(string.format("OnUnknownLayout called for %s", name))
	if name == "totemTimersFrame" then
		frame.totemTimersFrame:SetHeight(getTotemSize())
		frame.totemTimersFrame:ClearAllPoints()
		frame.totemTimersFrame:SetPoint("BOTTOMLEFT", frame, "TOPLEFT")
		--frame.totemTimersFrame:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT")
	end
end

function PitBull_TotemTimers:OnClearUnitFrame(unit, frame)
	if frame.totemTimersFrame then
		for i=1, MAX_TOTEMS do
			frame.totemTimersFrame.elements[i] = delFrame(frame.totemTimersFrame.elements[i].frame)
		end
		frame.totemTimersFrame = delFrame(frame.totemTimersFrame)
	end
end


function PitBull_TotemTimers:OnUpdateLayout(unit, frame)
	if unit ~= "player" then
		return
	end
	
	self:ResizeMainFrame(frame)
	
	--[[
	if frame.totemTimersFrame then
		local ttf = frame.totemTimersFrame
		for i=1, ttf:GetNumPoints() do
			local point, relativeTo, relativePoint, xOfs, yOfs = ttf:GetPoint(1)
			PitBull:Print(string.format("AnchorPoint(%d) is: point = %s, relativeTo = %s, relativePoint = %s", i, point, relativeTo:GetName(), relativePoint))
		end
	end
	]]--
	local old = not unitsShown[frame]
	local now = not frame.totemTimersFrame or not frame.totemTimersFrame:IsShown()
	if old == now then
		return
	end
	unitsShown[frame] = not now
	if not now then
		self:OnUpdateFrame(unit, frame)
	end
end

----------------------------------------------
-- Configuration registration(s?)

PitBull_TotemTimers:RegisterPitBullOptionsMethod(function(group)
	if group == "player" then
		return {
			name = L["Totem Timers"],
			desc = L["Totem timers for this unit type."],
			type = 'group',
			args = {
				hide = {
					type = 'boolean',
					name = L["Enable"],
					desc = L["Enables the Totem timers."],
					get = getEnabled,
					set = setEnabled,
					order = 1,
				},
				totemsize = {
					type = 'number',
					name = L["Totem Size"],
					desc = L["Sets the size of the individual totem icons."],
					min = 5,
					max = 100,
					step = 1,
					get = getTotemSize,
					set = setTotemSize,
					order = 2,
					disabled = getDisabled,
				},
				totemspacing = {
					type = 'number',
					name = L["Totem Spacing"],
					desc = L["Sets the size of the gap between the totem icons."],
					min = 0,
					max = 100,
					step = 1,
					get = getTotemSpacing,
					set = setTotemSpacing,
					order = 3,
					disabled = getDisabled,
				},
				totemdirection = {
					type = 'choice',
					name = L["Totem Direction"],
					desc = L["Choose wether to grow horizontally or vertically."],
					get = getTotemDirection,
					set = setTotemDirection,
					choices = {
						["h"] = L["Horizontal"],
						["v"] = L["Vertical"]
					},
					order = 4,
					disabled = getDisabled,
				},
				totemtooltips = {
					type = 'boolean',
					name = L["Totem Tooltips"],
					desc = L["Enables tooltips when hovering over the icons."],
					get = getTotemTooltips,
					set = setTotemTooltips,
					order = 5,
					disabled = getDisabled,
				},
				mainbgcolor = {
					type = 'color',
					name = L["Background Color"],
					desc = L["Sets the color and transparency of the background of the timers."],
					hasAlpha = true,
					get = getMainBGColor,
					set = setMainBGColor,
					disabled = getDisabled,
				},
				grptimerspiral = {
					type = 'group',
					name = L["Spiral Timer"],
					desc = L["Options relating to the spiral display timer."],
					args = {
						timerspiral = {
							type = 'boolean',
							name = L["Timer Spiral"],
							desc = L["Shows the pie-like cooldown spiral on the icons."],
							get = getTimerSpiral,
							set = setTimerSpiral,
							order = 1,
							disabled = getDisabled,
						},
						suppressocc = {
							type = 'boolean',
							name = L["Suppress OmniCC"],
							desc = L["Suppresses OmniCC on the spiral timer. (Requires UI reload to change the setting!)"],
							get = getSuppressOCC,
							set = setSuppressOCC,
							order = 2,
							disabled = function() return not getTimerSpiral() end,
						},
					},
				},
				grptimertext = {
					type = 'group',
					name = L["Text Timer"],
					desc = L["Options relating to the text display timer."],
					args = {
						timertext = {
							type = 'boolean',
							name = L["Timer Text"],
							desc = L["Shows the remaining time in as text."],
							get = getTimerText,
							set = setTimerText,
							order = 1,
							disabled = getDisabled,
						},
						timertextcolor = {
							type = 'color',
							name = L["Text Color"],
							desc = L["Color of the timer text."],
							hasAlpha = true,
							get = getTimerTextColor,
							set = setTimerTextColor,
							disabled = function() return not getTimerText() end
						},
						timertextside = {
							name = L["Text Side"],
							desc = L["Which side to position the timer text at."],
							type = "choice",
							choices = {
								topinside = "Top, Inside",
								topoutside = "Top, Outside",
								bottominside = "Bottom, Inside",
								bottomoutside = "Bottom, Outside",
								leftoutside = "Left, Outside",
								rightoutside = "Right, Outside",
								middle = "Middle",
							},
							get = getTimerTextSide,
							set = setTimerTextSide,
							disabled = function() return not getTimerText() end,
						},
						timertextscale = {
							name = L["Text Scale"],
							desc = L["Change the scaling of the text timer. Note: It's relative to PitBull's font size."],
							type = 'number',
							min = 0.1,
							max = 2,
							step = 0.01,
							get = getTimerTextScale,
							set = setTimerTextScale,
							disabled = function() return not getTimerText() end,
						},
					},
				},
			}
		}
	end
end)
